package com.f.job;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import service.HttpUtils;
import service.Push;
import service.Sys_emp;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.List;

/**
 * Created by 刘宇飞 on 2017/3/7.
 */
@Component
public class PushEventJob implements  IJob{

 //   @Scheduled(cron = "0 0 2 * * ?")   //每天凌晨2点执行1次
    @Scheduled(cron="0 */30 *  * * ? ")   //每30分执行一次
// @Scheduled(cron="0/5 * *  * * ? ")   //每5秒执行一次
    @Override
    public void execute() {
        //headers参数
       Map<String,String> headers = new HashMap<String,String>();
        Map<String,String> params = new HashMap<String,String>();
       // System.out.println("进入测试");
        params.clear();
        SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); //格式化当前系统日期
        String dateTime = dateFm.format(new java.util.Date());
        params.put("dateInfo",   dateTime);

        String url = "http://221.209.17.178:8080/app/getMyTodoEventsNotice";
        headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
      //  System.out.print("**********"+HttpUtils.doPostStr(url, headers, params, ""));
        String json=HttpUtils.doPostStr(url, headers, params, "");
        List<Sys_emp> sys_empList= JSON.parseArray(json, Sys_emp.class);
        String empstr="";
        for(Sys_emp emp:sys_empList){
            empstr+=emp.getLogin_name()+",";
        }
        empstr= empstr.substring(0,empstr.length()-1);
        Push push=new Push("A6905854936324", "D05BF950-9FB2-18C7-F4B6-B5F551EAF01B","");
        push.pushMessage("待处理事件", "您所在的单位有一个待处理事件", 2, 2, "all", "empstr");
 }
}
